import logging

from config import BASE_HOST


class RechargeApi:

    def __init__(self, ses):
        # 接收session对象的变量
        self.ses = ses

    # 获取充值验证码接口
    def get_recharge_verify_code(self,r):
        url = BASE_HOST + f'/common/public/verifycode/{r}'
        resp = self.ses.get(url=url)
        logging.info(f"获取充值验证码接口的响应状态码：{resp}")
        return resp

    # 充值接口
    def recharge(self, amount,valicode):
        # 定义一个字典变量，用来接收请求体数据
        data_dict = {"paymentType":"chinapnrTrust",
                     "amount": amount,
                     "formStr": "reForm",
                     "valicode": valicode}
        url=BASE_HOST+'/trust/trust/recharge'
        resp=self.ses.post(url=url,data=data_dict)
        logging.info(f'充值接口的响应体数据:{resp.json()}')
        return resp
    # 第三方充值接口
    def third_recharge(self,url,form_dict):
        resp = self.ses.post(url=url,data=form_dict)
        logging.info(f'第三方充值接口的响应体数据:{resp.text}')
        return resp
